package justcommunicate;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.swing.JTextArea;
import javax.swing.JTextField;

public class TextReciever extends SocketServer implements Runnable{
	JTextArea textField;
	public TextReciever(JTextArea textField) {
		this.textField = textField;
	}
	@Override
	protected void display(InputStream in) {
		BufferedReader r = new BufferedReader(new InputStreamReader(in));
		String temp = null;
		StringBuffer bf = new StringBuffer();
		try {
			while ((temp = r.readLine()) != null) {
				bf.append(temp);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String text = SocketServer.SERVER_IP + " said: " + bf.toString();
		System.out.println(text);
		textField.setText(textField.getText() + "\r\n" + text);
	}
	@Override
	public void run() {
		start();
	}

}
